︠1399bbdf-b25a-40e7-9c76-bc904be5ca09i︠ %html

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

Creative Commons License


Further Plotting Techiques in Sage

Thanks to Sage's integration of projects like matplotlib and Jmol, Sage has comprehensive plotting capabilities. This worksheet aims to go somewhat in depth with them. In particular, we will be looking at 2D plotting functionality (also see the 2D Graphics documentation page).
︡0be37d1a-d8c3-42b6-b0c7-2e46ef7ef4be︡{"done":true,"html":"\n

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

\n

\"Creative


\n

\n Further Plotting Techiques in Sage\n

\n Thanks to Sage's integration of projects like matplotlib and Jmol, Sage has comprehensive plotting capabilities. This worksheet aims to go somewhat in depth with them. In particular, we will be looking at 2D plotting functionality (also see the 2D Graphics documentation page).
"} ︠8eb91146-3730-4b7d-8cf6-c10c1f6c67dfi︠ %html

Cartesian Plots

A simple quadratic is easy.Note that alternatively, you can also use plot(x^2,-2,2) or plot(x^2,xmin=-2,xmax=2).
︡980a1956-e3c4-47d7-9eaf-925159c3cffe︡{"done":true,"html":"\n

\n Cartesian Plots\n

\n A simple quadratic is easy.Note that alternatively, you can also use plot(x^2,-2,2) or plot(x^2,xmin=-2,xmax=2).
"} ︠7114bdd4-6beb-4d39-84f7-52d1885649b4s︠ plot(x^2,(x,-2,2)) ︡5cc0ed96-6dcb-4260-97ac-3c22b336d6cb︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_1ALN8I.svg","show":true,"text":null,"uuid":"4629ee03-e3d8-496c-b1e5-f0205b655ca5"},"once":false}︡{"done":true}︡ ︠891cf39b-2acb-41cd-8dd3-8e9484403d7ci︠ %html You can combine graphics object by adding them. ︡8808cb04-f33c-4396-8e70-9c47513fe5e2︡{"done":true,"html":"\nYou can combine graphics object by adding them."} ︠6ef3a1fc-202d-404b-9a8c-26f03f49c909s︠ regular = plot(x^2,(x,-2,2),color="purple") skinny = plot(4*x^2,(x,-2,2),color="darkgreen") regular + skinny ︡aa785756-16a9-4145-896a-4e7864790623︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_lRqYA0.svg","show":true,"text":null,"uuid":"b9f5b4e2-c67c-4148-b99a-5165a185657d"},"once":false}︡{"done":true}︡ ︠f40f181f-32e1-48ab-bc62-a94aea77d135i︠ %html Problem: Plot a green $y=\sin(x)$ together with a red $y=2\cos(x)$. Note that you can use pi as part of your range. ︡c376e496-dbea-4095-951b-f03598a23d80︡{"done":true,"html":"\nProblem: Plot a green $y=\\sin(x)$ together with a red $y=2\\cos(x)$. Note that you can use pi as part of your range.\n"} ︠144ecb5a-e292-4752-8410-15dea4390f66︠ ︡cd809d4c-98a1-4d86-9e86-35230a5c1692︡ ︠7c62d995-9a29-4b88-ab19-c124afe89066i︠ %html Boundaries of a plot can be specified, in addition to the overall size. ︡697e5e3a-5a20-4372-a965-060c593a14f4︡{"done":true,"html":"\nBoundaries of a plot can be specified, in addition to the overall size."} ︠2c2511ba-94ce-430e-8968-4751e602cba8s︠ plot(1+e^(-x^2),xmin=-2,xmax=2,ymin=0,ymax=2.5,figsize=10) ︡d814de56-a6c0-4699-8797-38b1bc76a4e9︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_lYkRcC.svg","show":true,"text":null,"uuid":"ada46515-ec1e-4d6a-89d4-2e1db76f8100"},"once":false}︡{"done":true}︡{"done":true}︡ ︠1fa628b3-5a08-4039-aa91-150ebf99b09ci︠ %html Problem: Plot $y=5+3 \sin(4x)$ with suitable boundaries. ︡93bbd135-8fa6-4d19-bc02-b51eb49ed703︡{"done":true,"html":"\nProblem: Plot $y=5+3 \\sin(4x)$ with suitable boundaries."} ︠6cc22a80-25d0-49da-a17d-a1adab859a9d︠ ︡a4e9113b-433d-4197-8517-bcaa384d831b︡ ︠795073bf-22fd-4636-9fec-96743cb4020ai︠ %html You can add lots of extra information. ︡ff8150f9-d3a7-46ef-8103-4de626f4624c︡{"done":true,"html":"\nYou can add lots of extra information."} ︠6e5b258f-9905-49dd-8a27-0a3d7ac2cc4cs︠ exponential = plot(1+e^(-x^2),xmin=-2,xmax=2,ymin=0,ymax=2.5) max_line = plot(2,xmin=-2,xmax=2,ymin=0,ymax=2.5, linestyle="-.", color="red") min_line = plot(1,xmin=-2,xmax=2,ymin=0,ymax=2.5, linestyle=":", color="magenta") exponential + max_line + min_line ︡fe18462b-e628-4e71-953a-5f420bd0958e︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_b3dPZ3.svg","show":true,"text":null,"uuid":"defa4be3-6d57-49c9-95bb-ff978fcc10c6"},"once":false}︡{"done":true}︡ ︠45ac074b-6525-4baf-be51-0ba2e123efcei︠ %html You can fill regions with transparent color, and thicken the curve. This example uses several such options. ︡b7263974-267b-4b11-ae1f-3af907914768︡{"done":true,"html":"\nYou can fill regions with transparent color, and thicken the curve. This example uses several such options."} ︠77ab76a6-24f4-4f63-b74d-2f4dd7767173s︠ exponential = plot(1+e^(-x^2),xmin=-2,xmax=2,ymin=0,ymax=2.5,fill=.5,fillcolor='grey',fillalpha=.3) min_line = plot(1,xmin=-2,xmax=2,ymin=0,ymax=2.5, linestyle="-", thickness=6,color="magenta") exponential + min_line ︡d424061d-52cf-42b0-b6ff-44552d08bfd7︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_EyYjNC.svg","show":true,"text":null,"uuid":"7a17a0cc-1b66-4e5e-9ae4-6f9cc357dbed"},"once":false}︡{"done":true}︡ ︠dbf248d9-e7ff-4948-9119-ef21141fd45ai︠ %html You can also combine plots using the sum function and list comprehension. ︡eb41cd6b-6247-44f4-bc43-1b4a1259fb91︡{"done":true,"html":"\nYou can also combine plots using the sum function and list comprehension."} ︠35f3aa72-694e-4a06-80be-17215f1812c7s︠ sum([plot(x^n,(x,0,1), color=rainbow(5)[n]) for n in range(5)]) ︡4fd0ee34-f1ef-45b7-a71a-d7463de0c3cc︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_xC_IAZ.svg","show":true,"text":null,"uuid":"471b9799-3df7-4cf3-b6c9-d1b87e45f85a"},"once":false}︡{"done":true}︡ ︠0782a8bd-53bb-4a62-b20a-b5ebbd2d067bi︠ %html Problem: Create a plot showing the cross-section area for the following solid of revolution problem:
Consider the area bounded by $y=x^2-3x+6$ and the line $y=4$. Find the volume created byrotating this area around the line $y=1$.
(Note: You don't have to calculate this volume, all we want here is the appropriate picture of the cross-section.)
︡9648f934-2659-4500-95b9-0bf348db7197︡{"done":true,"html":"\nProblem:\nCreate a plot showing the cross-section area for the following solid of revolution problem:
\n Consider the area bounded by $y=x^2-3x+6$ and the line $y=4$. Find the volume created byrotating this area around the line $y=1$.
\n(Note: You don't have to calculate this volume, all we want here is the appropriate picture of the cross-section.)
"} ︠6fc61bfb-5fd4-4810-bf83-5d94fc82c62d︠ ︡0a42f86a-501d-44d9-987f-756577b4510a︡ ︠dae1a3e4-8a44-431b-a3e4-ed41e0e55445i︠ %html You can also label the axes and add labels to your graphs. ︡1276c28c-4cb0-475a-8dbc-6878b731a5f1︡{"done":true,"html":"\nYou can also label the axes and add labels to your graphs."} ︠ea2e55dc-e77b-49fe-8f01-463f3225e84fs︠ p = plot(sin(pi*x), -pi, pi, legend_label='f(x) = sin(pi x)', color="red", linestyle="--") p.axes_labels(['x','y=f(x)']) p.show() ︡ccaafe12-299c-464d-b37e-32918bcea22a︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_n2f2m8.svg","show":true,"text":null,"uuid":"20c9e70c-be8d-4b87-8c5d-819a3dec1ad4"},"once":false}︡{"done":true}︡ ︠c1fd9f46-865a-4b7b-bd80-8c9d6defce7ai︠ %html Here is an example where we combine two such plots, using $\LaTeX$ typesetting for the labels: ︡5d062b99-13eb-4938-ac48-2ff60c0cd247︡{"done":true,"html":"\nHere is an example where we combine two such plots, using $\\LaTeX$ typesetting for the labels:\n"} ︠b19b5505-8da9-4e8e-9995-5e40f5379c01s︠ p1 = plot(sin(pi*x), -pi, pi, legend_label='$f(x) = \sin(\pi x)$', color="red", linestyle="--",axes_labels=['$x$','$y$']) p2 = plot(cos(pi*x), -pi, pi, legend_label='$g(x) = \cos(\pi x)$', color="blue", linestyle=":",axes_labels=['$x$','$y$']) p1 + p2 ︡7fcc0941-1bfc-4b97-b07f-d1cba97bf08a︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_7kHSzy.svg","show":true,"text":null,"uuid":"bf9ded99-48cd-46ba-9827-d47f9f12c39b"},"once":false}︡{"done":true}︡ ︠f783e356-7579-42ad-b127-02d29cf0fe08i︠ %html Problem: In econmics, a demand curve $q(p) = \frac{1000}{p}-10$ relates the quantity $q$ demanded by the market of some product to its price $p$. Plot this function with appropriate informative labels. ︡82569fa9-9540-4694-a180-7f690876fbe6︡{"done":true,"html":"\nProblem:\nIn econmics, a demand curve $q(p) = \\frac{1000}{p}-10$ relates the quantity $q$ demanded by the market of some product to its price $p$. Plot this function with appropriate informative labels."} ︠f5990ef4-0ac3-4c50-ba3d-92fbe5d0ecca︠ ︡8c61dc03-8b6d-4d50-95ea-f9d22704ec21︡ ︠c9a42a3b-dda4-46ad-a355-ff812c124d76i︠ %html You can also add grid lines to a plot, or frame it. Have a look at the following examples. ︡8d83124d-eeb0-468d-8ed2-6b6e2b0fb9a7︡{"done":true,"html":"\nYou can also add grid lines to a plot, or frame it. Have a look at the following examples."} ︠cae9784b-b077-479a-8577-faa045522d4cs︠ plot(x^3-x,-2,2,gridlines=True,frame=False) plot(x^3-x,-2,2,gridlines='minor',frame=True) plot(x^3-x,-2,2,gridlines=True,frame=True) plot(x^3-x,-2,2,gridlines='minor',frame=False) plot(x^3-x,-2,2,gridlines=False,frame=False) plot(x^3-x,-2,2,gridlines=False,frame=False) ︡e326e00e-d351-4650-a362-74cd63f9b949︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_S6pKap.svg","show":true,"text":null,"uuid":"d06b6307-ead9-4cd2-a5ae-63d6c43b6313"},"once":false}︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_1mAYdR.svg","show":true,"text":null,"uuid":"e6cbcb85-7125-4619-bace-bb1562bda894"},"once":false}︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_zzCXDS.svg","show":true,"text":null,"uuid":"ef7a3908-341d-4a34-8420-da154051a329"},"once":false}︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_z7ArZ3.svg","show":true,"text":null,"uuid":"08c8a545-50be-4ff9-aa93-1d76ca9b18f4"},"once":false}︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_kegV4j.svg","show":true,"text":null,"uuid":"e7def3ad-22a7-4dc0-9fcc-8afbf090fd39"},"once":false}︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_P6ipWv.svg","show":true,"text":null,"uuid":"491a0122-8982-4a50-a1e8-8d40ba925d15"},"once":false}︡{"done":true}︡ ︠88df7328-226e-4982-b132-e4c57f0b8f87i︠ %html Here is an example where we add an arrow and some text to a plot. ︡876af715-125f-4dc9-8789-5edc600bcc07︡{"done":true,"html":"\nHere is an example where we add an arrow and some text to a plot."} ︠eea5c177-7f19-4da7-a3a2-ef9373c3b189s︠ tangent_line=plot(2*x,-2,2,gridlines='minor',color="red") curve = plot(x^2+1,-2,2) big_dot= point((1,2), size=60) the_arrow = arrow((0.2,2.8),(0.9,2.1)) the_words = text('f(x) = x^2+1 and tangent line at (1,2)', (0.5,-2.75),fontsize=20,color="black") big_image=tangent_line+curve+big_dot+the_arrow+the_words big_image.show() ︡ea5a1579-071f-464a-929b-643086ce2ce6︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_w88Z8B.svg","show":true,"text":null,"uuid":"234fdb5e-f430-422a-add8-d1da67c8adaf"},"once":false}︡{"done":true}︡ ︠677b5271-5ef6-47e1-a76f-d3a9b1e25dcbi︠ %html We can add text (using $\LaTeX$ typesetting) to graph an integral. ︡ddb7bf8a-6bdf-4bf0-8c5e-06f4e2071f8b︡{"done":true,"html":"\nWe can add text (using $\\LaTeX$ typesetting) to graph an integral."} ︠d5e8ba4f-bbf3-410e-a06c-cd861bdd0219s︠ p1= plot(sqrt(x),0,2,fill=True) p2=text('$\int_0^2 \sqrt{x}\,dx$',(0.5,1.1),fontsize=20,color='black') p1 + p2 ︡77f7f05b-529b-46b5-b8e1-66b7ea5ded3a︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_uG_mHh.svg","show":true,"text":null,"uuid":"45e53364-bb22-4262-b8c6-42fed72a5790"},"once":false}︡{"done":true}︡ ︠654b78e1-8575-48df-ae6f-e86e4444486ci︠ %html Problem: Graph the integral for the function $\sqrt{x}-1$ for $x$ between $0$ and $2$. ︡7eb8ee28-58f9-4a70-94de-db7527a1e5f7︡{"done":true,"html":"\nProblem:\nGraph the integral for the function $\\sqrt{x}-1$ for $x$ between $0$ and $2$.\n"} ︠51776797-ae08-4342-9f0c-d9348cb15cbc︠ ︡706a8fc1-f176-4d18-9f00-cde0ef18cb7a︡ ︠cddef212-70c7-4b4d-812c-dadc543ca1f3i︠ %html

Parametric Plots

A parametric plot needs a list of two functions of the parameter, i.e., it is a function $t\mapsto (x(t), y(t))$ and thus from the one-dimensional space $\mathbb{R}$ to the two-dimensional space $\mathbb{R}^2$. Notice that we must declare $t$ as a variable first (the variable $x$ is automatically declared as such in Sage). Because the following graphic is slightly wider than it is tall, we use the aspect_ratiooption (such options are also called keywords) to ensure the axes are correct for how we want to view this object.
︡efca1cf0-050b-48b3-ae12-44d3f4fefccc︡{"done":true,"html":"\n

\n Parametric Plots\n

\n A parametric plot needs a list of two functions of the parameter, i.e., it is a function $t\\mapsto (x(t), y(t))$ and thus from the one-dimensional space $\\mathbb{R}$ to the two-dimensional space $\\mathbb{R}^2$. Notice that we must declare $t$ as a variable first (the variable $x$ is automatically declared as such in Sage). Because the following graphic is slightly wider than it is tall, we use the aspect_ratiooption (such options are also called keywords) to ensure the axes are correct for how we want to view this object.
"} ︠4a5d1bca-7702-4bca-aaaf-1bbb2eb52294s︠ t=var('t') parametric_plot([cos(t)+3*cos(t/9),sin(t)-3*sin(t/9)],(t,0,18*pi),fill=True,aspect_ratio=1) ︡3f68e36e-982a-49df-9fd2-935f1bcc7853︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_tcL_kO.svg","show":true,"text":null,"uuid":"43997129-20c9-4732-838a-455a4f4bf8d9"},"once":false}︡{"done":true}︡ ︠ff7d4362-8bd1-4dee-a9e8-7df91c661991i︠ %html Problem: The following parametric equations will create a so-called hypocycloid: $$x(t) = 17*\cos(t)+3*\cos(17t/3)$$ $$y(t) = 17*\sin(t)-3*\sin(17t/3)$$ Create this as a parametric plot. ︡f6b49a55-1952-45f1-b6fc-f38bacd7a941︡{"done":true,"html":"\nProblem:\nThe following parametric equations will create a so-called hypocycloid:\n $$x(t) = 17*\\cos(t)+3*\\cos(17t/3)$$\n $$y(t) = 17*\\sin(t)-3*\\sin(17t/3)$$\n Create this as a parametric plot."} ︠342aadee-1a85-4ada-9f9c-9b0e0a3e010e︠ ︡79165055-d9b5-47d2-acf7-f4ba32b24475︡ ︠a31fc253-b44b-4140-a637-8d1b3cc8b87di︠ %html Sage automatically plots a 2D or 3D plot, a curve or a surface, depending on how many variables and coordinates you specify. Have a look at the following examples (move the 3D examples around). ︡d419009c-bd96-4cf4-8605-3d1bbcaf5a19︡{"done":true,"html":"\nSage automatically plots a 2D or 3D plot, a curve or a surface, depending on how many variables and coordinates you specify. Have a look at the following examples (move the 3D examples around)."} ︠a7f4c601-216c-40c6-9566-c618a192a802s︠ t=var('t') parametric_plot([log(1+t^2),sin(t)],(t,0,pi)) ︡7dddd809-78f8-4fdf-b5cb-01811bd72c48︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_ai34MQ.svg","show":true,"text":null,"uuid":"e68e5a43-a9b2-481f-83ed-435cd8797d1f"},"once":false}︡{"done":true}︡ ︠a508148b-e239-4109-bcbc-02dfda928544s︠ t=var('t') parametric_plot3d([log(1+t^2),sin(t),cos(t)],(t,0,6*pi)) ︡c049d77a-0473-4c83-8640-ba2a9012d7e6︡{"file":{"filename":"e213be43-e476-4d93-85a3-8614d1a92098.sage3d","uuid":"e213be43-e476-4d93-85a3-8614d1a92098"}}︡{"done":true}︡ ︠515bbc2a-bff7-404b-9847-195b9033c922s︠ t,r=var('t,r') parametric_plot([log(1+t^2),sin(r*t),cos(r*t)],(t,0,pi),(r,-1,1)) ︡1c4f7545-b9b4-403b-b550-74fe251ac506︡{"file":{"filename":"b7d0b313-8407-47ff-be4e-65e40850996f.sage3d","uuid":"b7d0b313-8407-47ff-be4e-65e40850996f"}}︡{"done":true}︡ ︠c9f609cb-b6ca-4c28-af22-9f20f7b79e30i︠ %html Problem: A neat example where we can use parametric plots are Lissajous Curves. These are curves of the form $$x(t) = \sin(a t) \qquad y(t)=\sin(b t)$$ where $t\in [0,2\pi]$ and $a$ and $b$ are some relatively prime natural numbers. Draw a few such Lissajous Curves, changing $a$ and $b$ and observing how the curve changes accordingly. ︡9115db8e-d542-4cc4-af1f-6a408473bda0︡{"done":true,"html":"\nProblem: A neat example where we can use parametric plots are Lissajous Curves. These are curves of the form \n $$x(t) = \\sin(a t) \\qquad y(t)=\\sin(b t)$$\nwhere $t\\in [0,2\\pi]$ and $a$ and $b$ are some relatively prime natural numbers. Draw a few such Lissajous Curves, changing $a$ and $b$ and observing how the curve changes accordingly.\n"} ︠7e8d0a8f-650b-42ce-976c-f98aff2f39dc︠ ︡9c08ec1a-e2ee-4ff2-852e-10921d783ea2︡ ︠49bf4d64-b807-48b5-87aa-e049e80a11cd︠ ︡17e09b22-5863-4b0f-a3b4-ca2c8927a35d︡ ︠52d3f570-1c54-4cc6-8dd4-6268e1af2df3i︠ %html

Polar Plots

Sage can do polar plots - from your knowledge of complex numbers (and their polar form) can you figure out how they work? So, here a curve called a cardioid:
︡497970f4-65cf-4c47-bdac-c03831998ed5︡{"done":true,"html":"\n

\n Polar Plots\n

\n Sage can do polar plots - from your knowledge of complex numbers (and their polar form) can you figure out how they work? So, here a curve called a cardioid:
"} ︠f2331925-dd95-407c-b6db-e84b0737d911s︠ polar_plot(2+2*cos(x),(x,0,2*pi),color=hue(0.8),thickness=4) ︡df45220f-747a-4e8b-b346-2c583eccda84︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_RhGA4s.svg","show":true,"text":null,"uuid":"24a3c5d7-0698-41c4-9aba-9752b2dbd455"},"once":false}︡{"done":true}︡ ︠998e1c60-8992-43f4-8936-e32848edf741i︠ %html More than one polar curve can be specified in a list. Notice the automatic graded shading of the fill color. ︡143ab63c-c40d-4448-a7e4-f06c621a6bab︡{"done":true,"html":"\nMore than one polar curve can be specified in a list. Notice the automatic graded shading of the fill color."} ︠949b07ce-4f71-495f-857b-6bfd3f814acfs︠ t=var('t') polar_plot([cos(4*t)+1.5, 0.5*cos(4*t)+2.5],(t,0,2*pi),color="darkgreen",thickness=2, fill=True,fillcolor='orange') ︡7f4e5acf-622b-484e-bf3c-6e2a6accd2fe︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_0trVp9.svg","show":true,"text":null,"uuid":"89510f03-ff8e-4d32-a24f-e23045bf4eb9"},"once":false}︡{"done":true}︡ ︠3c1830fa-199a-4c7f-8fe3-5f8cbac29ee1i︠ %html Problem: Create a plot for the following problem:
Find the area that is inside the circle $r=2$, but outside the cardioid $2+2 \cos(\theta)$.
︡58e6d0e7-7f5e-453a-a2dc-b38610f0199b︡{"done":true,"html":"\nProblem: Create a plot for the following problem:
\n Find the area that is inside the circle $r=2$, but outside the cardioid $2+2 \\cos(\\theta)$.
"} ︠05322369-d905-43be-af68-4bfc1e50e4f3︠ ︡c290b6fd-5ea6-43b8-aae4-9d56e7798cec︡ ︠682c84d0-d295-490e-9550-9e42d11a70c3i︠ %html Sometimes the default value of points Sage uses to generate a plot is too low, and the plot looks too "crinkly". Have a look at the following example: ︡62f03400-b818-41ec-8908-1a4095acd786︡{"done":true,"html":"\nSometimes the default value of points Sage uses to generate a plot is too low, and the plot looks too \"crinkly\". Have a look at the following example:"} ︠fda094ba-326d-4451-b230-3d9a30c8aa65s︠ polar_plot(exp(x/10),(x,-12*pi,12*pi)) polar_plot(exp(x/10),(x,-12*pi,12*pi), plot_points=1000) ︡18ce8b52-ba8b-4ea9-bcd0-c4e9f1edc75a︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_lhDIWG.svg","show":true,"text":null,"uuid":"98d3bb43-8e62-4bd2-bafd-a5ccc7007791"},"once":false}︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_iY_mnn.svg","show":true,"text":null,"uuid":"5b691f2a-66e6-417f-ab45-207c04918e68"},"once":false}︡{"done":true}︡ ︠c7554cfe-1caf-4b0c-8e8a-d28c51629468︠ %html

Plotting Data Points

Sometimes one wishes to simply plot some data points. Here we demonstrate several ways of plotting points and data via the simple approximation to the Fibonacci numbers given by $$F_n \approx \frac1{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n,$$ which is quite good after about $n=5$.
First, we notice that the Fibonacci numbers are build in.
︡40fcea11-ed99-4d4c-8108-61c66689eddc︡{"done":true,"html":"\n

\n Plotting Data Points\n

\n Sometimes one wishes to simply plot some data points. Here we demonstrate several ways of plotting points and data via the simple approximation to the Fibonacci numbers given by\n$$F_n \\approx \\frac1{\\sqrt{5}}\\left(\\frac{1+\\sqrt{5}}{2}\\right)^n,$$\nwhich is quite good after about $n=5$.
\n First, we notice that the Fibonacci numbers are build in.\n
"} ︠a772d8e1-fee1-4ab5-b808-c836dfd1cd06s︠ fibonacci_sequence(6) ︡151e759f-b063-4e01-8158-b48417a689da︡{"stdout":"\n"}︡{"done":true}︡ ︠5ff5293e-4e1a-4413-a2bd-c6a9f71931f0s︠ list(fibonacci_sequence(6)) ︡40e39c99-0a3f-4830-97ff-decb573ef391︡{"stdout":"[0, 1, 1, 2, 3, 5]\n"}︡{"done":true}︡ ︠b72e7868-30e3-4025-ab2c-656b637605aas︠ list(enumerate(fibonacci_sequence(6))) ︡5d8f2a31-104e-44ef-b9aa-b3f933f6c9c3︡{"stdout":"[(0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5)]\n"}︡{"done":true}︡ ︠b5c8e44f-3b9a-450e-a0df-36217873cc91i︠ %html In this cell, we just define the numbers and coordinate pairs we are about to plot. ︡e61f8aab-843d-4022-b62b-0c5cc849edb9︡{"done":true,"html":"\nIn this cell, we just define the numbers and coordinate pairs we are about to plot."} ︠069a8a4f-f368-4848-b0d1-cfdb59051240s︠ n = var('n') fibonacci = list(enumerate(fibonacci_sequence(6))) f(n)= (1/sqrt(5))*((1+sqrt(5))/2)^n asymptotic = [ (i, f(i)) for i in range(6)] ︡1395fe40-7f5f-4dfb-99c6-95908954f465︡{"done":true}︡ ︠56ddba49-7cd4-4a4c-a56f-1761c44b4107s︠ fibonacci ︡cff4e094-0cce-4c16-a78c-4c97faaf4ba3︡{"stdout":"[(0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5)]\n"}︡{"done":true}︡ ︠a6cb074a-ee1c-47b5-8d77-2a5715bd08cds︠ asymptotic ︡0748eb89-feee-4c5b-9e74-106749d5f5a5︡{"stdout":"[(0, 1/5*sqrt(5)), (1, 1/10*sqrt(5)*(sqrt(5) + 1)), (2, 1/20*sqrt(5)*(sqrt(5) + 1)^2), (3, 1/40*sqrt(5)*(sqrt(5) + 1)^3), (4, 1/80*sqrt(5)*(sqrt(5) + 1)^4), (5, 1/160*sqrt(5)*(sqrt(5) + 1)^5)]\n"}︡{"done":true}︡ ︠587e4971-bddb-48cd-bc24-d655259966fes︠ show(asymptotic) ︡2a372d71-c7fd-49c3-9b19-8ced8bb74ee1︡{"html":"
[($\\displaystyle 0$, $\\displaystyle \\frac{1}{5} \\, \\sqrt{5}$), ($\\displaystyle 1$, $\\displaystyle \\frac{1}{10} \\, \\sqrt{5} {\\left(\\sqrt{5} + 1\\right)}$), ($\\displaystyle 2$, $\\displaystyle \\frac{1}{20} \\, \\sqrt{5} {\\left(\\sqrt{5} + 1\\right)}^{2}$), ($\\displaystyle 3$, $\\displaystyle \\frac{1}{40} \\, \\sqrt{5} {\\left(\\sqrt{5} + 1\\right)}^{3}$), ($\\displaystyle 4$, $\\displaystyle \\frac{1}{80} \\, \\sqrt{5} {\\left(\\sqrt{5} + 1\\right)}^{4}$), ($\\displaystyle 5$, $\\displaystyle \\frac{1}{160} \\, \\sqrt{5} {\\left(\\sqrt{5} + 1\\right)}^{5}$)]
"}︡{"done":true}︡ ︠e1145414-a073-483b-be3d-b7877ae39fa9i︠ %html And here we plot not just the two sets of points, but also use several of the documented options for plotting points; the choice of markers for different data is particularly helpful for generating publishable graphics. ︡575f7377-936b-45db-83ff-8186202d3d1b︡{"done":true,"html":"\nAnd here we plot not just the two sets of points, but also use several of the documented options for plotting points; the choice of markers for different data is particularly helpful for generating publishable graphics."} ︠6da60030-4349-444a-8a5b-9313df65414ds︠ fib_plot=list_plot(fibonacci, color="red",marker="o",size=40) asy_plot=line(asymptotic,marker="D",color="black",thickness=2) show(fib_plot+asy_plot,aspect_ratio=1,figsize=12) ︡8756ad9a-6b83-4820-83e7-53c0fe6b9c30︡{"file":{"filename":"/projects/a717257b-7b34-4f0a-bccc-47996d6ed607/.sage/temp/compute7-us/17920/tmp_NgGaOo.svg","show":true,"text":null,"uuid":"04562848-273d-4202-b7ec-a6cbe2cefa84"},"once":false}︡{"done":true}︡ ︠bfebeed4-9ffc-45fd-b2c5-1f38b0709601︠ ︠eefb3dc8-926c-4b05-9a29-121426a84489︠